<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">




<title>Spring.NET学习笔记16——事务管理(应用篇) Level 200 - 刘冬的备忘录 - 博客园</title>
<meta name="keywords" content="Spring.NET,AOP,事务管理,ADO.NET">



<link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/GoodHelper/rss">
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/GoodHelper/rsd.xml"> 
  



<link rel="stylesheet" type="text/css" href="index.css" media="all">
</head>
<body><div style="border: 1px solid rgb(126, 152, 214); margin: 0px; padding: 1px; position: absolute; background-color: rgb(231, 247, 247); font-size: 14px; left: 3px; top: 3px; width: 138px; height: 22px; text-align: center; z-index: 99; display: none;" id="_dict_status"></div><div style="margin: 0px; padding: 0px; position: absolute; display: none; width: 240px; z-index: 98; background-color: rgb(255, 255, 255);" id="_dict_layer"><table style="border: 1px solid rgb(126, 152, 214);" border="0" cellpadding="0" cellspacing="0" width="240"><tbody><tr><td style="border: medium none ; margin: 0px; padding: 0px;" width="100%"><div style="border: medium none ; margin: 0px; padding: 0px; width: 240px; height: 20px; cursor: move; background-color: rgb(200, 218, 243); display: inline;"><table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td style="border: medium none ; margin: 0px; padding: 0pt 3px; background-color: rgb(200, 218, 243); color: rgb(26, 145, 0); font-size: 14px; line-height: 20px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;" id="_dict_title" name="_dict_title" align="left" height="20" width="60%">划词翻译 - Dict.CN</td><td style="border: medium none ; margin: 0px; padding: 0pt 3px; background-color: rgb(200, 218, 243); line-height: 20px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;" align="right" height="20" valign="middle"><a href="http://dict.cn/scb/" target="_top" title="生词本" style="border: medium none ; margin: 0px; padding: 0px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;" id="_dict_add" name="_dict_add"><img src="add.gif" style="border: medium none ; margin: 0px; padding: 0px; display: inline;" align="absmiddle" border="0"></a> <a href="http://dict.cn/" target="_top" title="详细解释" style="border: medium none ; margin: 0px; padding: 0px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;" id="_dict_detail" name="_dict_detail"><img src="detail.gif" style="border: medium none ; margin: 0px; padding: 0px; display: inline;" align="absmiddle" border="0"></a> <a href="http://dict.cn/foot/help.htm" target="_top" title="帮助" style="border: medium none ; margin: 0px; padding: 0px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;"><img src="help.gif" style="border: medium none ; margin: 0px; padding: 0px; display: inline;" align="absmiddle" border="0"></a> <a href="javascript:_dictClose()" title="关闭" target="_self" style="border: medium none ; margin: 0px; padding: 0px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;"><img src="close.gif" style="border: medium none ; margin: 0px; padding: 0px; display: inline;" align="absmiddle" border="0"></a></td></tr></tbody></table></div><table style="border: medium none ; margin: 0px; padding: 0px;" align="center" border="0" cellpadding="3" cellspacing="4" width="100%"><tbody><tr><td style="border: medium none ; margin: 0px; padding: 0px;"><fieldset color="#00c0ff" style="margin: 0px; padding: 0pt 2px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;"><legend align="center" style="margin: 0px; padding: 0px;"><a href="http://dict.cn/" target="_top" style="border: medium none ; margin: 0px; padding: 0px;"><img src="qdict.gif" border="0" height="53" width="126"></a></legend><table style="border: medium none ; margin: 0px; padding: 0px;" align="center" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="border: medium none ; margin: 0px; padding: 0px;" id="_dictContent" name="_dictContent" height="120" width="100%"><iframe id="_dictFrame" name="_dictFrame" src="index_1.html" frameborder="0" height="120" width="100%"></iframe></td></tr><tr align="center"><td style="border: medium none ; margin: 0px; padding: 0px; color: rgb(153, 153, 153); font-size: 10px; line-height: 18px; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;" height="18" valign="bottom" width="100%">©2003-2008 <a href="http://dict.cn/" target="_top" style="border: medium none ; margin: 0px; padding: 0px; color: rgb(46, 168, 237); font-size: 10px; line-height: 18px; text-decoration: none; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;">Dict.CN</a> <a href="http://dict.cn/" target="_top" style="border: medium none ; margin: 0px; padding: 0px; color: rgb(153, 153, 153); font-size: 10px; line-height: 18px; text-decoration: none; font-weight: normal; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;">海词</a></td></tr></tbody></table></fieldset></td></tr></tbody></table></td></tr></tbody></table></div>
    <form name="Form1" method="post" action="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html" id="Form1">
<div>
<input name="__EVENTTARGET" id="__EVENTTARGET" value="" type="hidden">
<input name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" type="hidden">
<input name="__VIEWSTATE" id="__VIEWSTATE" value="" type="hidden">
</div>




        
<!--done-->
<div id="home">
<div id="header">
	<div id="blogTitle">
	<a id="lnkBlogLogo" href="http://www.cnblogs.com/GoodHelper/"><img id="blogLogo" src="logo.gif" alt="返回主页"></a>			
		
<!--done-->
<h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/GoodHelper/">刘冬的备忘录</a></h1>
<h2>打造新疆第一敏捷团队</h2>



		
	</div><!--end: blogTitle 博客的标题和副标题 -->
	<div id="navigator">
		
<!--done-->
			<ul id="navList">
				<li><a id="MyLinks1_HomeLink" class="menu" href="http://www.cnblogs.com/">博客园</a></li>
				<li><a id="MyLinks1_SpaceLink" class="menu" href="http://space.cnblogs.com/">社区</a></li>
				<li><a id="MyLinks1_MyHomeLink" class="menu" href="http://www.cnblogs.com/GoodHelper/">首页</a></li>
				<li><a id="MyLinks1_NewPostLink" class="menu" href="http://www.cnblogs.com/GoodHelper/admin/EditPosts.aspx?opt=1">新随笔</a></li>
				<li><a id="MyLinks1_ContactLink" accesskey="9" class="menu" href="http://space.cnblogs.com/msg/send/%e5%88%98%e5%86%ac.NET">联系</a></li>
				<li><a id="MyLinks1_Admin" class="menu" href="http://www.cnblogs.com/GoodHelper/admin/EditPosts.aspx">管理</a></li>
				<li><a id="MyLinks1_Syndication" class="menu" href="http://www.cnblogs.com/GoodHelper/rss">订阅</a>
				<a id="MyLinks1_XMLLink" class="aHeaderXML" href="http://www.cnblogs.com/GoodHelper/rss"><img src="rss.gif" alt="订阅" style="border-width: 0px;"></a></li>
			</ul>


		<div class="blogStats">
			
			
<!--done-->
随笔- 32&nbsp;
文章- 2&nbsp;
评论- 226&nbsp;

			
		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->

<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		
					
<!--done-->
<div id="topics">
	<div class="post">
		<h1 class="postTitle">
			<a id="ctl04_TitleUrl" class="postTitle2" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html">Spring.NET学习笔记16——事务管理(应用篇) Level 200</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			　　目前有很多种数据访问技术。在.NET FCL中，有三类API可以执行事务管理，分别是ADO.NET、企业服务和<span style="color: rgb(51, 102, 255);">System.Transactions</span>。其它的数据访问技术，如对象关系映射（object relational mappers）和结果集映射（result-set mapping）等等的应用也很广泛，每种技术也都有自己的事务管理API。事务管理的代码一般是直接和各种事务API绑定在一起的，所以在开发时必须根据所用的具体技术来决定采用哪种API。但是，这种代码与事务API的紧耦合决定了很难通过简单的重构来解决更换数据访问技术的问题。而Spring.NET的事务框架允许在各种数据访问技术之上使用相同的API。通过配置或者集中的编程方式，可以很容易的更换后台事务API，而不需要对代码进行“大修”。 
<p>　　我们可以用业界公认的最佳方式来建立一种数据访问机制。Martin Fowler的著作《Patterns of Enterprise Application Architecture》讲到了许多在实际应用中非常成功的数据访问方法。其一便是在应用程序架构中引入一个数据访问层。数据访问层不仅要考虑到与不同的数据库和数据访问技术的兼容性，而且职责要严格限制在数据访问功能上。数据访问层应该只包含数据访问对象（<strong>DAO</strong>）以及“创建/获取/更新/删除”（<strong>CRUD</strong>，Create/Retrieve/Update/Delete）的操作，不应该涉及任何业务逻辑。业务逻辑应该位于单独的业务服务层，并且需要与一或多个DAO协作来完成高层次的用户功能。 </p>
<p>为了在事务中“要么全执行要么全不执行”这些用户功能，事务环境（transaction context）就应该由业务服务层（或某个“更高”的层次）控制。在实现上，一个很重要的细节是如何让<strong>DAO</strong>了解在其它层次中开始的“外部”事务。如果让<strong>DAO</strong>自己负责连接和事务的管理，就把问题看的过于简单化了，因为此时每个<strong>DAO</strong>都会执行自己的事务/资源管理，所以无法在同一事务中执行多个<strong>DAO</strong>操作。我们需要一种有效的手段，将连接/事务成对的从业务服务层传递给<strong>DAO</strong>。方法有很多种，最不具侵入性的就是将连接/事务作为方法参数显式的传递给<strong>DAO</strong>。另一种方法是将连接/事务放在线程本地存储内。不管使用哪种方法，只要在用ADO.NET，就必须得自己创建一个基础框架来完成这个任务。 </p>
<p>　　但是，等一下，企业服务不是能解决这个问题吗——还有<span style="color: rgb(51, 102, 255);">System.Transactions</span>命名空间呢？关于这个嘛，答案是对...也不对。企业服务确实能够让我们在事务环境中使用“原生”的<strong>ADO.NET</strong>在同一事务中执行多个<strong>DAO</strong>操作。但它的缺点是必须通过MS-DTC（Microsoft Distributed Transaction Coordinator）使用分布式（全局的）事务。如果只为了使用全局事务就必须依赖MS-DTC，那应用程序在性能上就会大打折扣了。 </p>
<p>使用.NET2.0新增<span style="color: rgb(51, 102, 255);">System.Transactions</span>命名空间下的<span style="color: rgb(51, 102, 255);">TransactonScope</span>类时，也有相同的问题。<span style="color: rgb(51, 102, 255);">TransactonScope</span>类的目的实际上是——用<span style="color: rgb(0, 0, 255);">using</span>语句使一段代码成为事务性代码。只要访问事务性的资源，<span style="color: rgb(0, 0, 255);">using</span>语句中的普通ADO.NET代码就会在一个ADO.NET本地事务中运行。但是，<span style="color: rgb(51, 102, 255);">System.Transactions</span>（和数据库）的“神奇“之处在于，如果需要访问第二个事务性资源，本地事务就会升级为分布式事务。这个过程叫做<strong>PSPE</strong>（Promotable Single Phase Enlistment）。此外，还需提醒读者：在同一个数据库上使用同一连接字符串打开第二个连接，就会使本地事务升级为分布式事务。所以，如果每个DAO都执行自己的连接管理，那就完了：本地事务会突然升级为分布式事务！如果应用程序只使用一个数据库，要想避免这个问题，就必须将唯一的连接对象传递给系统中的所有<strong>DAO</strong>。另外要注意的是某些数据库不支持<strong>PSPE</strong>，就算用单个数据库连接也会使用分布式事务（比如Oracle）。</p>
<p>Spring.NET的声明式事务管理功能非常强大。在数据库事务领域，讨论声明式事务管理的话题并不是很多，因为现在开发人员已经可以不再直接用凌乱繁复的事务API来进行事务管理了，而是可以通过在类和方法上应用某些特性来进行。但是在FCL中，只有企业服务提供了这一功能。Spring.NET则填补了这个空白——不管使用哪种事务管理技术：ADO.NET，还是（最常用的）<span style="color: rgb(51, 102, 255);">System.Transactions</span>，都可以使用声明式的事务管理。另外，企业服务也有自己的问题，举例来说，如果需要为查询/读取操作和创建/更新/删除操作设置不同的隔离等级，就必须将这两组操作分隔在不同的类中实现，因为在企业服务中，声明式事务的元数据只对类有效。但总的来说，企业服务，特别是在XP sp2和Server 2003中新出现的“无组件服务”，还有在应用程序进程内驻留的功能都是相当不错的。不过，虽然有这些优点，企业服务仍尚未在开发社区中引起很大的关注。</p>
<p><a href="http://www.cnblogs.com/GoodHelper/tag/Spring.NET/" target="_top">Spring.NET</a>事务管理的宗旨，就是要减轻FCL或第三方数据访问技术给开发人员带来的这些“痛苦”。它支持声明式事务管理，可以用配置方式获取事务选项的元数据——目前支持两种声明方式：在代码中用.NET特性声明；在IoC容器中用XML声明。</p>
<p>最后，<a href="http://www.cnblogs.com/GoodHelper/tag/Spring.NET/" target="_top">Spring.NET</a>事务管理还允许在同一事务中使用不同的数据访问技术——例如混合使用ADO.NET和<strong>NHibernate</strong>。</p>
<p>好了，再讲估计就有点烦人了，现在我们来看代码。 </p>
<p>　　在Spring.NET中，提供了以下实现类： </p>
<p>　　　　<span style="color: rgb(51, 102, 255);">AdoPlatformTransactionManager</span>- 基于本地ADO.NET的事务。</p>
<p>　　　　<span style="color: rgb(51, 102, 255);">ServiceDomainPlatformTransactionManager</span>- 由企业服务提供的分布式事务管理器。</p>
<p>　　　　<span style="color: rgb(51, 102, 255);">TxScopePlatformTransactionManager</span>- 由<span style="color: rgb(51, 102, 255);">System.Transactions</span>提供的本地/分布式的事务管理器。</p>
<p>&nbsp;&nbsp;</p>
<p>　　<span style="color: rgb(51, 102, 255);">ITransactionDefinition</span>接口封装了以下信息：</p>
<p>　　　　<span style="color: rgb(51, 102, 255);">Isolation</span>：该事务对其它事务操作的隔离级别。例如，用来表示某个事务是否能看到其它事务写入的、但尚未提交的信息。</p>
<p>　　　　<span style="color: rgb(51, 102, 255);">Propagation</span>：一般情况下，<span style="color: rgb(51, 102, 255);">TransactionScope</span>内的代码都会在为其指定的事务中运行。但是，该属性可用来设置如果某个事务环境已经存在时，该事务内的方法是否要执行：比如说，是简单的让它在现有事务中继续运行呢（这是一般情况），还是挂起现有事务然后创建一个新事务来运行。</p>
<p>　　　　<span style="color: rgb(51, 102, 255);">Timeout</span>：在超时（并且被事务基础框架自动回滚之前）前该事务可以运行多久。</p>
<p>　　　　<span style="color: rgb(51, 102, 255);">Read-only</span>状态：只读的事务不会修改任何数据。在某些情况下（比如使用<strong>NHibernate</strong>时），只读事务能显著提高性能。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;　　让我们从实现代码中学习<a href="http://www.cnblogs.com/GoodHelper/tag/Spring.NET/" target="_top">Spring.NET</a>事务管理的机制。<br>　　 准备条件：数据中建了2张表，如图1<br><img alt="" src="2009-11-16.10.gif" border="0" height="99" width="316"></p>
<p>UserTable为存储用户信息的表，AccountTable为存储用户账号的信息。<br></p>
<p>数据库访问层：</p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_195436" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_195436').style.display='none'; document.getElementById('Code_Open_Image_195436').style.display='inline'; document.getElementById('Code_Open_Text_195436').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_195436" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_195436').style.display='none'; getElementById('Code_Closed_Image_195436').style.display='inline'; getElementById('Code_Closed_Text_195436').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_195436">AccountDao</span><span id="Code_Open_Text_195436" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">interface</span><span style="color: rgb(0, 0, 0);">&nbsp;IAccountDao<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Create(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name,&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;userName);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Delete(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;userName);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;AccountDao&nbsp;:&nbsp;AdoDaoSupport,&nbsp;IAccountDao<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Create(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name,&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;userName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AdoTemplate.ExecuteNonQuery(CommandType.Text,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String.Format(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">INSERT&nbsp;INTO&nbsp;AccountTable&nbsp;(UserName,&nbsp;&nbsp;&nbsp;&nbsp;AccountName)&nbsp;VALUES&nbsp;('{0}',&nbsp;'{1}')</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;userName,&nbsp;name));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Delete(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;userName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AdoTemplate.ExecuteNonQuery(CommandType.Text,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String.Format(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">DELETE&nbsp;FROM&nbsp;AccountTable&nbsp;WHERE&nbsp;UserName&nbsp;=&nbsp;'{0}'</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;userName));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;} 
<div class="cnblogs_code"><img id="Code_Closed_Image_195520" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_195520').style.display='none'; document.getElementById('Code_Open_Image_195520').style.display='inline'; document.getElementById('Code_Open_Text_195520').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_195520" style="display: none;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_195520').style.display='none'; getElementById('Code_Closed_Image_195520').style.display='inline'; getElementById('Code_Closed_Text_195520').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_195520">UserDao</span><span id="Code_Open_Text_195520" style="display: none;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">interface</span><span style="color: rgb(0, 0, 0);">&nbsp;IUserDao<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Create(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;age);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Delete(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataSet&nbsp;Get(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;UserDao&nbsp;:&nbsp;AdoDaoSupport,&nbsp;IUserDao<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Create(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;age)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AdoTemplate.ExecuteNonQuery(CommandType.Text,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">.Format(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">INSERT&nbsp;INTO&nbsp;UserTable&nbsp;(UserName,&nbsp;&nbsp;&nbsp;&nbsp;UserAge)&nbsp;VALUES&nbsp;('{0}',&nbsp;{1})</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;name,&nbsp;age));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;Delete(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AdoTemplate.ExecuteNonQuery(CommandType.Text,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">.Format(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">DELETE&nbsp;FROM&nbsp;UserTable&nbsp;WHERE&nbsp;UserName&nbsp;=&nbsp;'{0}'</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;name));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;DataSet&nbsp;Get(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;AdoTemplate.DataSetCreate(CommandType.Text,&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">.Format(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">SELECT&nbsp;*&nbsp;FROM&nbsp;UserTable&nbsp;WHERE&nbsp;UserName&nbsp;=&nbsp;'{0}'</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;name));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div></span></span></div>
<p>&nbsp;</p>
<p>　　业务处理层：当我们插入用户信息后，需要为这个用户建立一个账号，当我们删除用户时，需要将帐号信息一起删除。这里我们就会用到了事务。<br></p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_195831" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_195831').style.display='none'; document.getElementById('Code_Open_Image_195831').style.display='inline'; document.getElementById('Code_Open_Text_195831').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_195831" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_195831').style.display='none'; getElementById('Code_Closed_Image_195831').style.display='inline'; getElementById('Code_Closed_Text_195831').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_195831">UserService</span><span id="Code_Open_Text_195831" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">interface</span><span style="color: rgb(0, 0, 0);">&nbsp;IUserService<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;SaveData(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;age,&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;accountName);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;DeleteData(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataSet&nbsp;Get(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;UserService&nbsp;:&nbsp;IUserService<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;IUserDao&nbsp;UserDao&nbsp;{&nbsp;</span><span style="color: rgb(0, 0, 255);">get</span><span style="color: rgb(0, 0, 0);">;&nbsp;</span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);">;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;IAccountDao&nbsp;AccountDao&nbsp;{&nbsp;</span><span style="color: rgb(0, 0, 255);">get</span><span style="color: rgb(0, 0, 0);">;&nbsp;</span><span style="color: rgb(0, 0, 255);">set</span><span style="color: rgb(0, 0, 0);">;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Transaction]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;SaveData(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;age,&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;accountName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserDao.Create(name,&nbsp;age);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AccountDao.Create(accountName,&nbsp;name);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Transaction]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;DeleteData(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserDao.Delete(name);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AccountDao.Delete(name);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Transaction(ReadOnly&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">)]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;DataSet&nbsp;Get(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;UserDao.Get(name);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p>&nbsp;</p>
<p>　　配置：<br></p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_195902" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_195902').style.display='none'; document.getElementById('Code_Open_Image_195902').style.display='inline'; document.getElementById('Code_Open_Text_195902').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_195902" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_195902').style.display='none'; getElementById('Code_Closed_Image_195902').style.display='inline'; getElementById('Code_Closed_Text_195902').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_195902">Dao.xml</span><span id="Code_Open_Text_195902" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml&nbsp;version="1.0"&nbsp;encoding="utf-8"&nbsp;</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">objects&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);"><span>="<a href="http://www.springframework.net/" class="smarterwiki-linkify">http://www.springframework.net</a>"</span></span><span style="color: rgb(255, 0, 0);">&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:db</span><span style="color: rgb(0, 0, 255);"><span>="<a href="http://www.springframework.net/database" class="smarterwiki-linkify">http://www.springframework.net/database</a>"</span></span><span style="color: rgb(255, 0, 0);">&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:tx</span><span style="color: rgb(0, 0, 255);"><span>="<a href="http://www.springframework.net/tx" class="smarterwiki-linkify">http://www.springframework.net/tx</a>"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">db:provider&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="DbProvider"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;provider</span><span style="color: rgb(0, 0, 255);">="SqlServer-1.1"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connectionString</span><span style="color: rgb(0, 0, 255);">="Server=(local);Database=SpringLesson16;Uid=sa;Pwd=;Trusted_Connection=False"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;<br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">object&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="userDao"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Dao.UserDao,&nbsp;Dao"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="AdoTemplate"</span><span style="color: rgb(255, 0, 0);">&nbsp;ref</span><span style="color: rgb(0, 0, 255);">="adoTemplate"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">object</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">object&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="accountDao"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Dao.AccountDao,&nbsp;Dao"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="AdoTemplate"</span><span style="color: rgb(255, 0, 0);">&nbsp;ref</span><span style="color: rgb(0, 0, 255);">="adoTemplate"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">object</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">object&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="userService"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Service.UserService,&nbsp;Service"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="UserDao"</span><span style="color: rgb(255, 0, 0);">&nbsp;ref</span><span style="color: rgb(0, 0, 255);">="userDao"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="AccountDao"</span><span style="color: rgb(255, 0, 0);">&nbsp;ref</span><span style="color: rgb(0, 0, 255);">="accountDao"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">object</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">object&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="adoTemplate"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Spring.Data.Core.AdoTemplate,&nbsp;Spring.Data"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="DbProvider"</span><span style="color: rgb(255, 0, 0);">&nbsp;ref</span><span style="color: rgb(0, 0, 255);">="DbProvider"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="DataReaderWrapperType"</span><span style="color: rgb(255, 0, 0);">&nbsp;value</span><span style="color: rgb(0, 0, 255);">="Spring.Data.Support.NullMappingDataReader,&nbsp;Spring.Data"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">object</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);">事务管理器</span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">object&nbsp;</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="transactionManager"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Spring.Data.Core.AdoPlatformTransactionManager,&nbsp;Spring.Data"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="DbProvider"</span><span style="color: rgb(255, 0, 0);">&nbsp;ref</span><span style="color: rgb(0, 0, 255);">="DbProvider"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">object</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);">事务切面</span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">tx:attribute-driven</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br><br></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">objects</span><span style="color: rgb(0, 0, 255);">&gt;</span></span></div>
<p>&nbsp;</p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_195920" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_195920').style.display='none'; document.getElementById('Code_Open_Image_195920').style.display='inline'; document.getElementById('Code_Open_Text_195920').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_195920" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_195920').style.display='none'; getElementById('Code_Closed_Image_195920').style.display='inline'; getElementById('Code_Closed_Text_195920').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_195920">App.config</span><span id="Code_Open_Text_195920" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml&nbsp;version="1.0"&nbsp;encoding="utf-8"&nbsp;</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;<br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">configSections</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">sectionGroup&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="spring"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">section&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="context"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Spring.Context.Support.ContextHandler,&nbsp;Spring.Core"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">section&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="objects"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Spring.Context.Support.DefaultSectionHandler,&nbsp;Spring.Core"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">section&nbsp;</span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="parsers"</span><span style="color: rgb(255, 0, 0);">&nbsp;type</span><span style="color: rgb(0, 0, 255);">="Spring.Context.Support.NamespaceParsersSectionHandler,&nbsp;Spring.Core"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">sectionGroup</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">configSections</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">spring</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">parsers</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">parser&nbsp;</span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="Spring.Data.Config.DatabaseNamespaceParser,&nbsp;Spring.Data"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">parser&nbsp;</span><span style="color: rgb(255, 0, 0);">type</span><span style="color: rgb(0, 0, 255);">="Spring.Transaction.Config.TxNamespaceParser,&nbsp;Spring.Data"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">parsers</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">context</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">resource&nbsp;</span><span style="color: rgb(255, 0, 0);">uri</span><span style="color: rgb(0, 0, 255);">="assembly://Dao/Dao/Dao.xml"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">context</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">spring</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br><br></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span></span></div>
<p>&nbsp;</p>
<p>　　我们新建一个单元测试：</p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_200135" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_200135').style.display='none'; document.getElementById('Code_Open_Image_200135').style.display='inline'; document.getElementById('Code_Open_Text_200135').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_200135" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_200135').style.display='none'; getElementById('Code_Closed_Image_200135').style.display='inline'; getElementById('Code_Closed_Text_200135').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_200135">TransactionTest</span><span id="Code_Open_Text_200135" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;[TestFixture]<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;TransactionTest<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Test]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;AdoTransaction()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IApplicationContext&nbsp;ctx&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;ContextRegistry.GetContext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IUserService&nbsp;service&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(IUserService)ctx.GetObject(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">userService</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service.SaveData(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">刘冬</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 128);">26</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">1233456</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p>&nbsp;</p>
<p>输出效果：两条数据已经插入数据库(图2)<br><img alt="" src="2009-11-16.11.gif" border="0">图2</p>
<p>&nbsp;</p>
<p>　　我们修改一下<span style="color: rgb(51, 102, 255);">UserService</span>的DeleteData方法，在调用&nbsp;UserDao.Delete(name)以后抛出异常，测试数据是否回滚。<br></p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_200936" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_200936').style.display='none'; document.getElementById('Code_Open_Image_200936').style.display='inline'; document.getElementById('Code_Open_Text_200936').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_200936" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_200936').style.display='none'; getElementById('Code_Closed_Image_200936').style.display='inline'; getElementById('Code_Closed_Text_200936').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_200936">DeleteData</span><span id="Code_Open_Text_200936" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Transaction]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;DeleteData(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserDao.Delete(name);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;Exception(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">测试数据是否回滚</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AccountDao.Delete(name);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p>&nbsp;</p>
<p>&nbsp;　　如果数据没有回滚，则我们得到的数据为UserTable表中没有数据，AccountTable表中有数据。<br></p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_201153" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_201153').style.display='none'; document.getElementById('Code_Open_Image_201153').style.display='inline'; document.getElementById('Code_Open_Text_201153').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_201153" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_201153').style.display='none'; getElementById('Code_Closed_Image_201153').style.display='inline'; getElementById('Code_Closed_Text_201153').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_201153">TransactionTest</span><span id="Code_Open_Text_201153" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;TransactionTest<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Test]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;AdoTransaction()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IApplicationContext&nbsp;ctx&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;ContextRegistry.GetContext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IUserService&nbsp;service&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(IUserService)ctx.GetObject(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">userService</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service.DeleteData(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">刘冬</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p>&nbsp;</p>
<p>输出效果：图3<br><img alt="" src="2009-11-16.12.jpg" border="0" height="409" width="922">图3</p>
<p>&nbsp;</p>
<p>　　我们发现数据已经回滚。<br></p>
<p>　　<a href="http://www.cnblogs.com/GoodHelper/tag/Spring.NET/" target="_top">Spring.NET</a>框架帮我们很好的管理了事务。但在我们的编码过程中经常使用到<span style="color: rgb(0, 0, 255);">try</span>...<span style="color: rgb(0, 0, 255);">catch</span>语句。要是在DeleteData方法中加入<span style="color: rgb(0, 0, 255);">try</span>...<span style="color: rgb(0, 0, 255);">catch</span>语句会回滚吗？我们修改一下<span style="color: rgb(51, 102, 255);">UserService</span>的SaveData方法<br></p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_202335" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_202335').style.display='none'; document.getElementById('Code_Open_Image_202335').style.display='inline'; document.getElementById('Code_Open_Text_202335').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_202335" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_202335').style.display='none'; getElementById('Code_Closed_Image_202335').style.display='inline'; getElementById('Code_Closed_Text_202335').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_202335">SaveData</span><span id="Code_Open_Text_202335" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Transaction]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;SaveData(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;name,&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;age,&nbsp;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&nbsp;accountName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserDao.Create(name,&nbsp;age);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AccountDao.Create(accountName,&nbsp;name);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">&nbsp;(Exception&nbsp;ex)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(ex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p>&nbsp;</p>
<p>当前的数据库AccountTable表中已经存在字段为AccountName的“<span style="color: rgb(128, 0, 0);">123456</span>”记录。因为AccountName字段是主键，我再插入一条数据就会出现异常。<br></p>
<div class="cnblogs_code"><img style="display: none;" id="Code_Closed_Image_202639" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_202639').style.display='none'; document.getElementById('Code_Open_Image_202639').style.display='inline'; document.getElementById('Code_Open_Text_202639').style.display='inline';" src="contractedblock.gif" align="top" height="16" width="11"><img id="Code_Open_Image_202639" style="display: inline;" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_202639').style.display='none'; getElementById('Code_Closed_Image_202639').style.display='inline'; getElementById('Code_Closed_Text_202639').style.display='inline';" src="expandedblockstart.gif" align="top" height="16" width="11"><span style="display: none;" class="cnblogs_code_Collapse" id="Code_Closed_Text_202639">AdoTransaction</span><span id="Code_Open_Text_202639" style="display: inline;"><br><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Test]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;AdoTransaction()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IApplicationContext&nbsp;ctx&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;ContextRegistry.GetContext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IUserService&nbsp;service&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;(IUserService)ctx.GetObject(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">userService</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;service.SaveData(</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">刘冬冬</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 128);">27</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">1233456</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<p>&nbsp;</p>
<p>输出效果：图4<br><img alt="" src="2009-11-16.13.jpg" border="0" height="377" width="703">图4</p>
<p>　　我们发现在使用<span style="color: rgb(0, 0, 255);">try</span>...<span style="color: rgb(0, 0, 255);">catch</span>语句以后并没有回滚。从以上的效果中，我们可以得出结论：使用<span style="color: rgb(0, 0, 255);">try</span>...<span style="color: rgb(0, 0, 255);">catch</span>的异常叫作“<strong>运行期异常</strong>”，<a href="http://www.cnblogs.com/GoodHelper/tag/Spring.NET/" target="_top">Spring.NET</a>的事务管理默认是不对<strong>运行期异常</strong>回滚的。</p>
<p>　　如果要实现没有<span style="color: rgb(0, 0, 255);">try</span>...<span style="color: rgb(0, 0, 255);">catch</span>语句不回滚事务，我们需要在方法上标记[<span style="color: rgb(51, 102, 255);">Transaction</span>(NoRollbackFor = <span style="color: rgb(0, 0, 255);">new </span><span style="color: rgb(51, 102, 255);">Type</span>[] { typeof(<span style="color: rgb(51, 102, 255);">Exception</span>) })]。NoRollbackFor 属性是<span style="color: rgb(51, 102, 255);">Type</span>数组，意思是运到<span style="color: rgb(51, 102, 255);">Exception</span>异常就不回滚，您也可以在增加其它的异常条件，如<span style="color: rgb(0, 0, 255);">t</span><span style="color: rgb(0, 0, 255);">ypeof</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(51, 102, 255);">ArithmeticException</span>)。这样，当遇到标有包含NoRollbackFor 属性的异常时，就不进行回滚。<br></p>
<p>　　<a title="代码管理" style="color: rgb(128, 128, 0);" href="http://download.csdn.net/source/1821510" target="_top">代码下载</a></p>
<p>&nbsp;</p>
<p>　　参考Spring.NET中文手册</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>　　<a href="http://www.cnblogs.com/GoodHelper/archive/2009/11/20/SpringNet_Index.html" target="_top">返回目录</a><br></p><div id="EntryTag">Tag标签: <a href="http://www.cnblogs.com/GoodHelper/tag/Spring.NET/">Spring.NET</a>,<a href="http://www.cnblogs.com/GoodHelper/tag/AOP/">AOP</a>,<a href="http://www.cnblogs.com/GoodHelper/tag/%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86/">事务管理</a>,<a href="http://www.cnblogs.com/GoodHelper/tag/ADO.NET/">ADO.NET</a></div>
<div id="digg_block">
<div id="div_digg">										
	<div class="diggit" onclick="DiggIt(1604069,58949,1)"> 
		<span class="diggnum" id="digg_count_1604069">0</span>
	</div>
	<div class="buryit" onclick="DiggIt(1604069,58949,2)"> 
		<span class="burynum" id="bury_count_1604069">0</span>
	</div>
	<div class="clear"></div>
	<span style="display: none;" id="span_isdigged_1604069">0</span>	
	<div class="diggword" id="digg_word_1604069">(请您对文章做出评价)</div>	
</div>
</div>
<div class="clear"></div>
<div id="post_next_prev">
<a href="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Aop_Config.html">« </a> 上一篇：<a href="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Aop_Config.html" title="发布于2009-11-16 02:26">Spring.NET学习笔记15——AOP的配置(基础篇) Level 200</a><br>
<a href="http://www.cnblogs.com/GoodHelper/archive/2009/11/17/SpringNet_Transaction_Required.html">» </a> 下一篇：<a href="http://www.cnblogs.com/GoodHelper/archive/2009/11/17/SpringNet_Transaction_Required.html" title="发布于2009-11-17 02:25">Spring.NET学习笔记17——事务传播行为(基础篇) Level 200</a><br>
</div>








		</div>
		<div class="postDesc">posted @ 2009-11-16 20:59 <a href="http://www.cnblogs.com/GoodHelper/">刘冬.NET</a> 阅读(1142) <a href="#commentform">评论(1)</a> &nbsp;<a href="http://www.cnblogs.com/GoodHelper/admin/EditPosts.aspx?postid=1604069">编辑</a> <a href="http://www.cnblogs.com/GoodHelper/AddToFavorite.aspx?id=1604069">收藏</a> <a href="#" onclick="PutInWz();return false;">网摘</a>  所属分类: <a href="http://www.cnblogs.com/GoodHelper/category/215413.html">Spring.NET</a></div>
	</div>
	<img src="1604069.html" height="1" width="1">
	
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html"
dc:identifier="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html"
dc:title=""
trackback:ping="http://www.cnblogs.com/GoodHelper/services/trackbacks/1604069.aspx" />
</rdf:RDF>
-->

</div><!--end: topics 文章、评论容器-->
<a name="pagedcomment"></a>
<!--done-->
<br>
<div class="feedback_area_title">发表评论</div>
<div class="feedbackNoItems"><span id="span_comment_maxid" style="display: none;">1746723</span></div>
	

		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<a onclick='ReplyComment("轻风随风",1746723,"q6f5Ikjrk5Mfm7OEfODG5X8BFX5ZUOwGu6/D1gtECOkgATXEeVMeBQ==")' href="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html#commentform">回复</a>&nbsp;&nbsp;<a onclick='QuoteComment(1746723,"q6f5Ikjrk5Mfm7OEfODG5X8BFX5ZUOwGu6/D1gtECOkgATXEeVMeBQ==")' href="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html#commentform">引用</a>&nbsp;&nbsp;<a title="查看该作者发表过的评论" href="http://www.cnblogs.com/CommentsByAuthor.aspx?author=%e8%bd%bb%e9%a3%8e%e9%9a%8f%e9%a3%8e" target="_top">查看</a>&nbsp;&nbsp;<a id="Comments1_CommentList_ctl00_DeleteLink" href="javascript:__doPostBack('Comments1$CommentList$ctl00$DeleteLink','')"></a>&nbsp;&nbsp;<a id="Comments1_CommentList_ctl00_EditLink" causesvalidation="False"></a>
				</div>
				<a href="#1746723">#1楼</a><a name="1746723" id="comment_anchor_1746723"></a><a name="Post"></a>2010-01-14 11:31 | <a id="Comments1_CommentList_ctl00_NameLink" href="http://home.cnblogs.com/69875/" target="_top">轻风随风</a>&nbsp;<a href="http://space.cnblogs.com/msg/send/%e8%bd%bb%e9%a3%8e%e9%9a%8f%e9%a3%8e" title="给此人发送站内短消息" class="sendMsg2This">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<span id="comment_body_1746723" class="blog_comment_body">这么好的文章为啥没人评论呢？<br>一直看楼主的这一系列文章，写的很好，对我有很大帮助。<br>再次感谢楼主，希望能多出好文章。</span><br>
			</div>
		</div>
	

<div id="ctl05_comment_form" class="commentform">




<div id="ctl05_divLoginPannel">
<div class="login_tips">注册用户登录后才能发表评论，请 <a href="http://passport.cnblogs.com/login.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fGoodHelper%2farchive%2f2009%2f11%2f16%2fSpringNet_Transaction.html%3flogin%3d1%23commentform" class="underline">登录</a> 或 <a href="http://passport.cnblogs.com/register.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fGoodHelper%2farchive%2f2009%2f11%2f16%2fSpringNet_Transaction.html%23Bottom2" class="underline">注册</a> 。</div>
</div>

<div class="itnews c_ad_block" id="itnews">
<a href="http://news.cnblogs.com/" target="_top">IT新闻</a>:<br>

          ·  <a href="http://news.cnblogs.com/n/55140/" target="_top">《星际争霸2》"刀锋女王"重金属主题音乐视频</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55139/" target="_top">中国站长最郁闷的几件事情</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55138/" target="_top">苹果Vs谷歌：手机领域谁怕谁？</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55137/" target="_top">摩托罗拉：豪赌Android的希望与隐忧</a><br>
	
          ·  <a href="http://news.cnblogs.com/n/55136/" target="_top">分众新坐标：楼宇是过去 未来在手机和互联网</a><br>
	
</div>


<div id="ad_under_comment" class="c_ad_block">
<a href="http://a4.yeshj.com/rd/34138/" target="_top">每天10分钟，轻松学英语</a><br><br>
<div id="google_ads_div_cnblogs_blogpost_bottom1">
<iframe src="index_2.html" style="border: 0pt none ;" marginheight="0" marginwidth="0" name="google_ads_iframe_cnblogs_blogpost_bottom1" id="google_ads_iframe_cnblogs_blogpost_bottom1" scrolling="no" frameborder="0" height="60" width="468"></iframe></div>

<br>
<div id="google_ads_div_cnblogs_blogpost_bottom">
<iframe src="index_3.html" style="border: 0pt none ;" marginheight="0" marginwidth="0" name="google_ads_iframe_cnblogs_blogpost_bottom" id="google_ads_iframe_cnblogs_blogpost_bottom" scrolling="no" frameborder="0" height="250" width="300"></iframe></div>

</div>
<div id="site_nav_under" class="c_ad_block">
网站导航：<br>
<a href="http://www.cnblogs.com/" target="_top">博客园首页</a> &nbsp;<a href="http://news.cnblogs.com/" target="_top">IT新闻</a> &nbsp;<a href="http://home.cnblogs.com/" target="_top">个人主页</a> &nbsp;<a href="http://home.cnblogs.com/ing/" target="_top">闪存</a> &nbsp;<a href="http://job.cnblogs.com/" target="_top">程序员招聘</a> &nbsp;<a href="http://space.cnblogs.com/" target="_top">社区</a> &nbsp;<a href="http://space.cnblogs.com/q/" target="_top">博问</a> &nbsp;<a href="http://wz.cnblogs.com/" target="_top">网摘</a>
</div>
<div id="ad_under_comment2" class="c_ad_block">
<a href="http://www.china-pub.com/STATIC07/0912/zh_ndcx_091212.asp" target="_top"><img src="chinapub_20091222.jpg" alt="" style="border: 0px none ;"></a><br>
<a href="http://www.china-pub.com/itbook/" target="_top">China-pub 计算机图书网上专卖店！6.5万品种2-8折！</a><br>
<a href="http://www.china-pub.com/static07/0901/zh_jueba_090121.asp" target="_top">China-Pub 计算机绝版图书按需印刷服务</a><br>
</div>

<div id="relative_search"><br><b>相关搜索:</b><br> <a href="http://zzk.cnblogs.com/s?w=Spring.NET" target="_top">Spring.NET</a> <a href="http://zzk.cnblogs.com/s?w=AOP" target="_top">AOP</a> <a href="http://zzk.cnblogs.com/s?w=%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86" target="_top">事务管理</a> <a href="http://zzk.cnblogs.com/s?w=ADO.NET" target="_top">ADO.NET</a> <a href="http://zzk.cnblogs.com/s?w=Spring.NET" target="_top">Spring.NET</a> </div><div id="relative_search"><br><b>在知识库中查看：</b><br> <a href="http://kb.cnblogs.com/a/1604069/">Spring.NET学习笔记16——事务管理(应用篇) Level 200</a></div>

</div>


				
	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->

	<div id="sideBar">
		<div id="sideBarMain">
			
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
	<div id="profile_block"><a href="http://home.cnblogs.com/GoodHelper/" target="_top">我的主页</a>&nbsp; <a href="http://home.cnblogs.com/GoodHelper/detail/" target="_top">个人资料</a><br><a href="http://home.cnblogs.com/GoodHelper/ing/" target="_top">我的闪存</a>&nbsp; <a href="http://space.cnblogs.com/msg/send/%e5%88%98%e5%86%ac.NET" target="_top">发短消息</a></div>
</div>

			
<div id="calendar">
<table id="Calendar1_entryCal" class="Cal" title="Calendar" border="0" cellpadding="0" cellspacing="0">
	<tbody><tr><td colspan="7"><table class="CalTitle" border="0" cellspacing="0">
		<tbody><tr><td class="CalNextPrev"><a href="javascript:__doPostBack('Calendar1$entryCal','V3622')" style="color: Black;" title="Go to the previous month">&lt;</a></td><td align="center">2010年1月</td><td class="CalNextPrev" align="right"><a href="javascript:__doPostBack('Calendar1$entryCal','V3684')" style="color: Black;" title="Go to the next month">&gt;</a></td></tr>
	</tbody></table></td></tr><tr><th class="CalDayHeader" abbr="日" scope="col" align="center">日</th><th class="CalDayHeader" abbr="一" scope="col" align="center">一</th><th class="CalDayHeader" abbr="二" scope="col" align="center">二</th><th class="CalDayHeader" abbr="三" scope="col" align="center">三</th><th class="CalDayHeader" abbr="四" scope="col" align="center">四</th><th class="CalDayHeader" abbr="五" scope="col" align="center">五</th><th class="CalDayHeader" abbr="六" scope="col" align="center">六</th></tr><tr><td class="CalOtherMonthDay" align="center">27</td><td class="CalOtherMonthDay" align="center">28</td><td class="CalOtherMonthDay" align="center">29</td><td class="CalOtherMonthDay" align="center">30</td><td class="CalOtherMonthDay" align="center">31</td><td align="center">1</td><td class="CalWeekendDay" align="center">2</td></tr><tr><td class="CalWeekendDay" align="center">3</td><td align="center">4</td><td align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td class="CalWeekendDay" align="center">9</td></tr><tr><td class="CalWeekendDay" align="center">10</td><td align="center">11</td><td align="center">12</td><td align="center">13</td><td align="center">14</td><td align="center">15</td><td class="CalWeekendDay" align="center">16</td></tr><tr><td class="CalTodayDay" align="center">17</td><td align="center">18</td><td align="center">19</td><td align="center">20</td><td align="center">21</td><td align="center">22</td><td class="CalWeekendDay" align="center">23</td></tr><tr><td class="CalWeekendDay" align="center">24</td><td align="center">25</td><td align="center">26</td><td align="center">27</td><td align="center">28</td><td align="center">29</td><td class="CalWeekendDay" align="center">30</td></tr><tr><td class="CalWeekendDay" align="center">31</td><td class="CalOtherMonthDay" align="center">1</td><td class="CalOtherMonthDay" align="center">2</td><td class="CalOtherMonthDay" align="center">3</td><td class="CalOtherMonthDay" align="center">4</td><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td></tr>
</tbody></table>
</div>

			
			<div id="leftcontentcontainer">
				

<div class="mySearch">
<h3 class="catListTitle">搜索</h3>
<div class="div_my_zzk"><input value="" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk" type="text">&nbsp;<input onclick="zzk_go()" value="找找看" id="btnZzk" class="btn_my_zzk" type="button"></div>
</div>
<div class="catListLink">
<h3 class="catListTitle">常用链接</h3>
<ul>

		<li><a id="SingleColumn1_ctl02_rptMainLinks_ctl00_lnkLinkItem" href="http://www.cnblogs.com/GoodHelper/MyPosts.html">我的随笔</a></li>
	
		<li><a id="SingleColumn1_ctl02_rptMainLinks_ctl01_lnkLinkItem" href="http://home.cnblogs.com/GoodHelper/">我的空间</a></li>
	
		<li><a id="SingleColumn1_ctl02_rptMainLinks_ctl02_lnkLinkItem" href="http://space.cnblogs.com/msg/recent">我的短信</a></li>
	
		<li><a id="SingleColumn1_ctl02_rptMainLinks_ctl03_lnkLinkItem" href="http://www.cnblogs.com/GoodHelper/MyComments.html">我的评论</a></li>
	
<li><a id="itemListLink" onclick="this.blur();WarpClass('itemListLink', 'itemListLin_con');return false;" href="#">更多链接</a></li>
</ul>
<div id="itemListLin_con" style="display: none;">
<ul>

		<li><a id="SingleColumn1_ctl02_repeaterLinks_ctl00_lnkLinkItem" title="我发表过评论的随笔" href="http://www.cnblogs.com/GoodHelper/OtherPosts.html">我的参与</a></li>
	
		<li><a id="SingleColumn1_ctl02_repeaterLinks_ctl01_lnkLinkItem" href="http://www.cnblogs.com/GoodHelper/MyNews.html">我的新闻</a></li>
	
		<li><a id="SingleColumn1_ctl02_repeaterLinks_ctl02_lnkLinkItem" href="http://www.cnblogs.com/GoodHelper/RecentComments.html">最新评论</a></li>
	
		<li><a id="SingleColumn1_ctl02_repeaterLinks_ctl03_lnkLinkItem" href="http://www.cnblogs.com/GoodHelper/tag/">我的标签</a></li>
	
</ul>
</div>
</div>

<div class="catListTag">
<h3 class="catListTitle">我的标签</h3>
<ul>
<li><a href="http://www.cnblogs.com/GoodHelper/tag/Spring.NET/">Spring.NET</a>(30)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/NHibernate/">NHibernate</a>(7)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/AOP/">AOP</a>(7)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/IoC/">IoC</a>(5)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/%e4%be%9d%e8%b5%96%e6%b3%a8%e5%85%a5/">依赖注入</a>(4)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/NVelocity/">NVelocity</a>(4)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/WCF/">WCF</a>(3)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/ASP.NET+MVC/">ASP.NET MVC</a>(3)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/Linq/">Linq</a>(3)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/DI/">DI</a>(3)</li><li><a href="http://www.cnblogs.com/GoodHelper/tag/">更多</a></li>
</ul>
</div>
<div class="catListPostCategory">
<h3 class="catListTitle">随笔分类<span style="font-size: 11px; font-weight: normal;">(36)</span></h3>

<ul>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl01_Link" href="http://www.cnblogs.com/GoodHelper/category/214139.html">NHibernate(7)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl01_RssLink" title="Subscribe to NHibernate(7)" href="http://www.cnblogs.com/GoodHelper/category/214139.html/rss">(rss)</a></li>

<li><a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl02_Link" href="http://www.cnblogs.com/GoodHelper/category/215413.html">Spring.NET(29)</a> <a id="SingleColumn1_Categories_CatList_ctl00_LinkList_ctl02_RssLink" title="Subscribe to Spring.NET(29)" href="http://www.cnblogs.com/GoodHelper/category/215413.html/rss">(rss)</a></li>

</ul>

</div>

<div class="catListPostArchive">
<h3 class="catListTitle">随笔档案<span style="font-size: 11px; font-weight: normal;">(28)</span></h3>

<ul>

<li><a id="SingleColumn1_Categories_CatList_ctl01_LinkList_ctl01_Link" href="http://www.cnblogs.com/GoodHelper/archive/2009/11.html">2009年11月 (20)</a> </li>

<li><a id="SingleColumn1_Categories_CatList_ctl01_LinkList_ctl02_Link" href="http://www.cnblogs.com/GoodHelper/archive/2009/10.html">2009年10月 (8)</a> </li>

</ul>

</div>

<div class="catListArticleCategory">
<h3 class="catListTitle">文章分类</h3>

<ul>

<li><a id="SingleColumn1_Categories_CatList_ctl02_LinkList_ctl01_Link" href="http://www.cnblogs.com/GoodHelper/category/214956.html">Spring.NET</a> <a id="SingleColumn1_Categories_CatList_ctl02_LinkList_ctl01_RssLink" title="Subscribe to Spring.NET" href="http://www.cnblogs.com/GoodHelper/category/214956.html/rss">(rss)</a></li>

</ul>

</div>

<div class="catListImageCategory">
<h3 class="catListTitle">相册</h3>

<ul>

<li><a id="SingleColumn1_Categories_CatList_ctl03_LinkList_ctl01_Link" href="http://www.cnblogs.com/GoodHelper/gallery/219559.html">广州宿舍</a> </li>

</ul>

</div>



<div class="catListBlogRank">
<h3 class="catListTitle">积分与排名</h3>
<ul>
	<li class="liScore">
		积分 -	51075
	</li><li class="liRank">
		排名 -	1473
	</li>
</ul>
</div>



<div class="catListEssay">
<h3 class="catListTitle">最新随笔</h3>
<ul>
	
	
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl00_RecentPostsList2_ctl00_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/21/SpringNet_blogs.html">1.&nbsp;Spring.NET学习笔记——前言</a></li>
		
			
	
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl01_RecentPostsList2_ctl00_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/20/SpringNet_NVelocity.html">2.&nbsp;Spring.NET学习笔记26——整合NVelocity(应用篇) Level 200</a></li>
		
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl01_RecentPostsList2_ctl01_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/20/SpringNet_Index.html">3.&nbsp;Spring.NET学习笔记——目录(原)</a></li>
		
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl01_RecentPostsList2_ctl02_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/20/SpringNet_QuartzNet.html">4.&nbsp;Spring.NET学习笔记25——整合Quartz.NET(应用篇) Level 200</a></li>
		
			
	
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl02_RecentPostsList2_ctl00_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/19/SpringNet_WebService.html">5.&nbsp;Spring.NET学习笔记21——整合Web Service(应用篇) Level 200</a></li>
		
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl02_RecentPostsList2_ctl01_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/19/SpringNet_Remoting.html">6.&nbsp;Spring.NET学习笔记20——整合Remoting(应用篇) Level 200</a></li>
		
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl02_RecentPostsList2_ctl02_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/19/SpringNet_Nhibernate_AspNetMvc.html">7.&nbsp;Spring.NET学习笔记19——整合NHibernate和ASP.NET MVC(基础篇) Level 300</a></li>
		
			
	
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl03_RecentPostsList2_ctl00_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/18/SpringNet_NHibernate.html">8.&nbsp;Spring.NET学习笔记18——整合NHibernate(基础篇) Level 300</a></li>
		
			
	
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl04_RecentPostsList2_ctl00_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/17/SpringNet_Transaction_Required.html">9.&nbsp;Spring.NET学习笔记17——事务传播行为(基础篇) Level 200</a></li>
		
			
	
			<li><a id="SingleColumn1_ctl06_RecentPostsList_ctl05_RecentPostsList2_ctl00_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html">10.&nbsp;Spring.NET学习笔记16——事务管理(应用篇) Level 200</a></li>
		
		
</ul>
</div>

<div class="catListComment">
<h3 class="catListTitle">最新评论<a id="SingleColumn1__1c5f994_RSSHyperlink1" title="RSS订阅最最新评论" href="http://www.cnblogs.com/GoodHelper/CommentsRSS.aspx"><img title="RSS订阅最最新评论" src="xml.gif" style="border-width: 0px;"></a></h3>

	
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__1c5f994_CommentList_ctl00_Hyperlink2" class="listitem" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/16/SpringNet_Transaction.html#1746723">1.&nbsp;Re:Spring.NET学习笔记16——事务管理(应用篇) Level 200</a>
			</div>
			<div class="divRecentComment">
				这么好的文章为啥没人评论呢？
一直看楼主的这一系列文章，写的很好，对我有很大帮助。
再次感谢楼主，希望能多出好文章。 (轻风随风)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__1c5f994_CommentList_ctl01_Hyperlink2" class="listitem" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/19/SpringNet_Nhibernate_AspNetMvc.html#1746697">2.&nbsp;Re:Spring.NET学习笔记19——整合NHibernate和ASP.NET MVC(基础篇) Level 300</a>
			</div>
			<div class="divRecentComment">
				今天带给大家的就是期待以久的ASP.NET MVC与Spring.NET和NHibernate的组合，视图打造.NET版的SSH(Spring-Struts-Hibernate)

很好很强大！ (shmilgmy)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__1c5f994_CommentList_ctl02_Hyperlink2" class="listitem" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/21/SpringNet_blogs.html#1746691">3.&nbsp;Re:Spring.NET学习笔记——前言</a>
			</div>
			<div class="divRecentComment">
				支持！期待lz王者归来:) (shmilgmy)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__1c5f994_CommentList_ctl03_Hyperlink2" class="listitem" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/11/SpringNet_Life.html#1741365">4.&nbsp;Re:Spring.NET学习笔记11——自定义对象行为(基础篇) Level 200</a>
			</div>
			<div class="divRecentComment">
				有点迷糊了，第二部分没看明白。
莫非只是“配置”上的继承，仅是为了简化配置的编写？ (鹤冲天)
			</div>		
		
			<div class="divRecentCommentAticle">
				<a id="SingleColumn1__1c5f994_CommentList_ctl04_Hyperlink2" class="listitem" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/11/SpringNet_Method.html#1741362">5.&nbsp;Re:Spring.NET学习笔记10——方法的注入(基础篇) Level 200</a>
			</div>
			<div class="divRecentComment">
				不可思议，没想到.Net也能这样用！ (鹤冲天)
			</div>		
		
</div>

<div class="catListView">
<h3 class="catListTitle">阅读排行榜</h3>
	
			<ul>
		
			<li>
				<a id="SingleColumn1_ctl08_TopList_ctl01_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/10/SpringNET_Framework_Step1.html">1.&nbsp;Spring.NET企业架构实践之 JQuery +  FlexiGrid + ASP.NET MVC + NVelocity + WCF + LINQ + NHibernate 综合应用(4064)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl08_TopList_ctl02_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/25/Spring_NET_IoC.html">2.&nbsp;Spring.NET学习笔记1——控制反转(基础篇) Level 200(3088)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl08_TopList_ctl03_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/16/linq2nhibernate.html">3.&nbsp;10分钟搞定Linq to NHibernate(一)——环境篇(2869)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl08_TopList_ctl04_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/25/SpringNET_Config.html">4.&nbsp;Spring.NET学习笔记2——环境搭建(基础篇) Level 200(2468)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl08_TopList_ctl05_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/25/SpringNET_Create.html">5.&nbsp;Spring.NET学习笔记4——对象的创建(基础篇) Level 200(1948)</a>
			</li>
		
			</ul>
		
</div>

<div class="catListFeedback">
<h3 class="catListTitle">评论排行榜</h3>
	
			<ul>
		
			<li>
				<a id="SingleColumn1_ctl09_TopList_ctl01_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/11/10/SpringNET_Framework_Step1.html">1.&nbsp;Spring.NET企业架构实践之 JQuery +  FlexiGrid + ASP.NET MVC + NVelocity + WCF + LINQ + NHibernate 综合应用(29)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl09_TopList_ctl02_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/16/linq2nhibernate.html">2.&nbsp;10分钟搞定Linq to NHibernate(一)——环境篇(28)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl09_TopList_ctl03_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/25/Spring_NET_IoC.html">3.&nbsp;Spring.NET学习笔记1——控制反转(基础篇) Level 200(22)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl09_TopList_ctl04_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/25/SpringNET_Create.html">4.&nbsp;Spring.NET学习笔记4——对象的创建(基础篇) Level 200(19)</a>
			</li>
		
			<li>
				<a id="SingleColumn1_ctl09_TopList_ctl05_Hyperlink1" href="http://www.cnblogs.com/GoodHelper/archive/2009/10/26/SpringNET_DI.html">5.&nbsp;Spring.NET学习笔记6——依赖注入(应用篇) Level 300(17)</a>
			</li>
		
			</ul>
		
</div>

			</div>
			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		
<!--done-->
Copyright ©2010 刘冬.NET
	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 --><a href="http://www.cnzz.com/stat/website.php?web_id=1738003" target="_top" title="站长统计"><img src="pic1.gif" border="0" hspace="0" vspace="0"></a><img src="stat.htm" border="0" height="0" width="0">

    </form>
	
	
      
    
    
    
</body>
</html>
